<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>

        <el-row :gutter="15">

        <el-col :lg="4" :md="12">
          <el-form-item label="姓名学号1:">
            <el-input
              clearable
              v-model="where.username"
              placeholder="请输入姓名或学号"/>
          </el-form-item>
        </el-col>

       <el-col :lg="4" :md="6">
         <el-form-item label="学年:">
           <el-select
             filterable
             clearable
             v-model="where.annual"
             @change="$forceUpdate()"
             size="small"
             placeholder="-请选择学年-"
             class="ele-block">
             <el-option v-for="item in annualList" :key="item.id" :label="item.name" :value="item.id"/>
           </el-select>
         </el-form-item>
        </el-col>



      <el-col :lg="4" :md="12">
         <el-form-item label="项目:">
           <el-select
             filterable
             clearable
             v-model="where.projectId"
             @change="$forceUpdate()"
             size="small"
             placeholder="-请选择项目-"
             class="ele-block">
             <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id"/>
           </el-select>
         </el-form-item>
      </el-col>


          <el-col :lg="11" :md="12">
            <el-form-item label="统计日期:">
              <el-col :lg="7" :md="12">
                <el-date-picker
                  type="date"
                  class="ele-fluid"
                  v-model="where.starttime"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  placeholder="开始时间"/>
              </el-col>
              <el-col :lg="2" :md="12">
                ——
              </el-col>
              <el-col :lg="7" :md="12">
                <el-date-picker
                  type="date"
                  class="ele-fluid"
                  v-model="where.endtime"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  placeholder="结束时间"/>
              </el-col>
            </el-form-item>
          </el-col>


        </el-row>
        <el-row :gutter="15">

       <el-col :lg="4" :md="12">
         <el-form-item label="选择年级:">
           <el-select
             filterable
             clearable
             v-model="where.gradeId"
             @change="$forceUpdate();getClassList()"
             size="small"
             placeholder="-请选择年级-"
             class="ele-block">
             <el-option v-for="item in gradeList" :key="item.id" :label="item.name" :value="item.id"/>
           </el-select>
         </el-form-item>
      </el-col>

      <el-col :lg="4" :md="12">
         <el-form-item label="院系:">
           <el-select
             filterable
             clearable
             v-model="where.departmentsId"
             @change="$forceUpdate();getProfessionalList();getClassList()"
             size="small"
             placeholder="-请选择所属院系-"
             class="ele-block">
             <el-option v-for="item in departmentsList" :key="item.id" :label="item.name" :value="item.id"/>
           </el-select>
         </el-form-item>
      </el-col>


      <el-col :lg="4" :md="12">
         <el-form-item label="专业:">
           <el-select
             filterable
             clearable
             v-model="where.professionalId"
             @change="$forceUpdate();getClassList()"
             size="small"
             placeholder="-请选择专业-"
             class="ele-block">
             <el-option v-for="item in professionalList" :key="item.id" :label="item.name" :value="item.id"/>
           </el-select>
         </el-form-item>
      </el-col>

      <el-col :lg="4" :md="12">
         <el-form-item label="班级:">
           <el-select
             filterable
             clearable
             v-model="where.classId"
             @change="$forceUpdate()"
             size="small"
             placeholder="-请选择班级-"
             class="ele-block">
             <el-option v-for="item in classList" :key="item.id" :label="item.name" :value="item.id"/>
           </el-select>
         </el-form-item>
      </el-col>

        <el-col :lg="3" :md="12">
          <el-form-item label="性别:">
            <el-select
              clearable
              v-model="where.gender"
              placeholder="全部"
              class="ele-fluid">
              <el-option label="男" value="1"/>
              <el-option label="女" value="2"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :lg="6" :md="12">
          <div class="ele-form-actions">
            <el-button
              type="primary"
              icon="el-icon-search"
              class="ele-btn-icon"
              @click="reload">查询
            </el-button>
            <el-button @click="reset">重置</el-button>
          <!--  <el-button
              size="small"
              type="success"
              icon="el-icon-download"
              class="ele-btn-icon"
              @click="exportExcel">导出
            </el-button> -->
          </div>
        </el-col>
      </el-row>


      </el-form>

      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        height="calc(100vh - 315px)">
       <!-- <template slot="toolbar">
            <el-button
              @click="exportExcel"
              type="primary"
              icon="el-icon-download"
              class="ele-btn-icon"
              size="small">导出
            </el-button>
          </template> -->
          <template slot="toolbar">
          	<el-button
          		@click="removeBatch"
          		type="danger"
          		icon="el-icon-delete"
          		class="ele-btn-icon"
          		size="small">批量删除
          	</el-button>
          </template>
        <!-- 性别列 -->
        <template slot="gender" slot-scope="{row}">
          <el-tag
            :type="['success', 'primary', 'warning'][row.gender-1]"
            size="mini">
            {{ ['男', '女', '保密'][row.gender - 1] }}
          </el-tag>
        </template>
        <!-- 头像 -->
        <template slot="avatar" slot-scope="{row}">
          <el-avatar shape="square" :size="25" :src="row.avatar"/>
        </template>
        <!-- 设备类型列 -->
        <template slot="device" slot-scope="{row}">
          <el-tag
            :type="['primary','success','warning', 'danger', 'info'][row.device-1]"
            size="mini">
            {{ ['苹果', '安卓', 'WAP站', 'PC站', '后台'][row.device - 1] }}
          </el-tag>
        </template>
        <!-- 注册来源列 -->
        <template slot="source" slot-scope="{row}">
          <el-tag
            :type="['primary','success','warning', 'danger', 'info'][row.source-1]"
            size="mini">
            {{ ['APP注册', '小程序注册', '网站注册', 'WAP站注册', '马甲会员'][row.source - 1] }}
          </el-tag>
        </template>
        <!-- 状态列 -->
        <template slot="status" slot-scope="{row}">
          <el-switch
            v-model="row.status"
            @change="editStatus(row)"
            :active-value="1"
            :inactive-value="2"/>
        </template>
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
          <el-link
            type="primary"
            v-if="row.videoUrlList"
            :underline="false"
            @click="SeeVideo(row)">视频
          </el-link>
	        <el-link v-if="row.reportUrl"
	                 type="primary"
	                 :underline="false"
	                 @click="openWeb(row.reportUrl)">体测报告
	        </el-link>
          <el-link type="danger" icon="el-icon-delete" circle @click="removeOne(row)"></el-link>
          <div class="videoshow" :id="row.videoId" v-show="row.videoshow">
            <span class="videoclose" @click="closevideo(row)">关闭</span>
          <a-modal
             title="视频播放"
             :width="600"
             :visible="viewVideo"
             :footer="null"
             @cancel="handleCancel"
          >
             <video
                 :src="row.videoUrlList"
                  width="500"
                  controls="controls"
             ></video>
          </a-modal>
          </div>
        </template>
      </ele-pro-table>
    </el-card>

  </div>


</template>

<script>
import {mapGetters} from "vuex";
import XLSX from 'xlsx';

export default {
  name: 'Delrecord',
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/sport/delrecord',
      // 表格列配置
      columns: [
        // {
        //   columnKey: 'selection',
        //   type: 'selection',
        //   width: 45,
        //   align: 'center',
        //   fixed: "left"
        // },
        {
          prop: 'id',
          label: 'ID',
          width: 80,
          align: 'center',
          showOverflowTooltip: true,
          fixed: "left"
        },
        {
          prop: 'projectName',
          label: '项目',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
        },
        {
          prop: 'testerName',
          label: '姓名',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'testerNumber',
          label: '学籍号',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'score',
          label: '运动成绩',
          sortable: 'custom',
          align: 'center',
          width: 150,
          resizable: false,
        },
        {
          prop: 'duration',
          label: '运动耗时',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'bmi',
          label: 'BMI',
          showOverflowTooltip: true,
          minWidth: 120,
          align: 'center',
        },
        {
          prop: 'pingscore',
          label: '评分',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'ratingStr',
          label: '等级',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'gender',
          label: '性别',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 60,
          slot: 'gender'
        },
        {
          prop: 'grade',
          label: '年级',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'departName',
          label: '院系名称',
          align: 'center',
          width: 80,
          resizable: false,
        },
        {
          prop: 'professionalName',
          label: '专业',
          align: 'center',
          width: 80,
          resizable: false,
        },
        {
          prop: 'clazz',
          label: '专业班级',
          align: 'center',
          width: 80,
          resizable: false,
        },
        {
          prop: 'createdDate',
          label: '运动时间',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 160,
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 150,
          align: 'center',
          resizable: false,
          slot: 'action',
          fixed: "right"
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      // 是否显示导入弹窗
      showImport: false,

      projectList: [],
      gradeList: [],
      departmentsList: [],
      professionalList: [],
      classList: [],
      annualList:[],
      viewVideo:false,
      videoUrl:'',
      showvid:false,
    };
  },
  mounted() {
    this.getGradeList()
  },
  methods: {
			  openWeb: function (urls) {
				  this.$router.push({path: '/newWebView/newWebView', query: {urls: urls}});
			  },
        SeeVideo(row){
          var that = row;
          that.videoshow = true;
          this.$refs.vueRef.play();//播放
        },
        closevideo(row){
          var that = row;
          that.videoshow = false;
        },

        // 取消预览
        handleCancel(e) {
          this.viewVideo = false;
          this.$refs.vueRef.pause();//暂停
        },


    getGradeList() {
      this.$http.get("/project/getProjectList").then(response => {
        if (response.data.code === 0) {
          this.projectList = response.data.data
        }else {
          this.$message.error(response.data.msg);
        }
      })

      this.$http.get("/grade/index?limit=99999").then(response => {
        if (response.data.code === 0) {
          this.gradeList = response.data.data
        } else {
          this.$message.error(response.data.msg);
        }
      })

      this.$http.get('/professional/index?limit=99999').then(res => {
        if (res.data.code === 0) {
          this.professionalList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      })

      this.$http.get('/departments/index?limit=99999').then(res => {
        if (res.data.code === 0) {
          this.departmentsList = res.data.data;
          this.getProfessionalList();
          this.getClassList();
        } else {
          this.$message.error(res.data.msg);
        }
      })

     this.$http.get('/annual/index?limit=99999').then(res => {
       if (res.data.code === 0) {
         this.annualList = res.data.data;
       } else {
         this.$message.error(res.data.msg);
       }
     })


      this.reload()
    },
    /**
     * 获取专业列表
     */
    getProfessionalList() {
      if(this.where.professionalId){
        delete this.where.classId
      }
      this.$http.post('/professional/getProfessionalList',{type: this.where.stype,sid:this.where.departmentsId}).then(res => {
        if (res.data.code === 0) {
          this.professionalList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
      this.getClassList();
    },
    /**
     * 获取班级列表
     */
    getClassList() {
      if(this.where.departmentsId){
        this.where.classId = null;
        this.$forceUpdate();
      }
      this.$http.post('/clss/getClassList',{yid:this.where.departmentsId,gid:this.where.gradeId,pid:this.where.professionalId,stype:this.where.stype}).then(res => {
        if (res.data.code === 0) {
          this.classList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /* 导出数据Excel */


    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示编辑 */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    showVideo(url){
      console.log(url);
      // url = row.videoUrlList;
      window.open(url , "_blank");
    },
    /* 删除 */
    removeOne(row) {
      this.$confirm('确定要删除吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/sport/deleter', {id: row.id}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据')
        return;
      }
      this.$confirm('确定要删除选中的记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/sport/deleter', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message({type: 'success', message: res.data.msg});
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
    /* 更改状态 */
    editStatus(row) {
      const loading = this.$loading({lock: true});
      let params = Object.assign({
        "id": row.id,
        "status": row.status
      })
      this.$http.post('/member/status', params).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message({type: 'success', message: res.data.msg});
        } else {
          row.status = !row.status ? 1 : 2;
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    }
  }
}
</script>

<style scoped>
</style>

<style>

  span.el-link--inner {
      background: #A4ADB3;
      color: white;
      font-size: 12px;
      padding: 2px 4px;
      border-radius: 5px;
  }
  .videoshow {
      position: fixed;
      left: 20%;
      top: 20%;
      width: 850px;
      background: #f3f2f2;
  }
  video{
    padding:10px 5px 5px;
    padding-top: 30px;
    width:800px;
  }
  .videoclose{
      position: absolute;
      float: right;
      border-radius: 37px;
      display: block;
      margin-left: 780px;
      margin-top: 3px;
      background: #e6dddd;
      padding: 2px 4px;
  }
  </style>
